from fabric import Connection
import tarfile
import os

with tarfile.open('../unpackage.tar', 'w') as tar:
    tar.add('../unpackage', arcname='unpackage')
c = Connection("root@121.5.109.215")
with c.cd('/root/rain/lamb-uniapp/_deploy'):
    c.run("rm -rf ../unpackage", pty=True)
    c.put('../unpackage.tar', '/root/rain/lamb-uniapp')
    c.put('./Dockerfile', '/root/rain/lamb-uniapp/_deploy')
    c.put('./docker-compose.yml', '/root/rain/lamb-uniapp/_deploy')
    c.put('./nginx.conf', '/root/rain/lamb-uniapp/_deploy')
    c.run("cd .. && tar xvf /root/rain/lamb-uniapp/unpackage.tar && cd _deploy", pty=True)
    c.run("./start.sh", pty=True)
    c.run("docker ps", pty=True)
os.remove('../unpackage.tar')
